package reflect;

import reflect.annotation.AutoRunClass;
import reflect.annotation.AutoRunMethod;

import java.lang.reflect.Method;
import java.util.Scanner;

public class Test4 {
    public static void main(String[] args) throws Exception {
        Scanner scan = new Scanner(System.in);
        System.out.println("请输入类名:");
        String className = scan.nextLine();
        Class cls = Class.forName(className);
        if ((cls.isAnnotationPresent(AutoRunClass.class))) {
            System.out.println(cls.getName() + "类");
            Object obj = cls.newInstance();
            Method[] method = cls.getMethods();
            for (Method method1 : method) {
                if (method1.isAnnotationPresent(AutoRunMethod.class)) {
                    System.out.println(method1.getName() + "方法:");
                    method1.invoke(obj);
                }
            }
        } else {
            System.out.println("类不符合条件");
        }
    }
}
